package org.example.vueadminapi2.controller;

import jakarta.annotation.Resource;
import org.example.vueadminapi2.dto.Result;
import org.example.vueadminapi2.entity.TestPlan;
import org.example.vueadminapi2.service.TestPlanService;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Objects;

@RestController
public class TestPlanController {
/**
 * @FileName: TestPlanController
 * @Description:
 * @Author: cyx
 * @date: 2025-02-26
 **/
    @Resource
    private TestPlanService TestPlanService;
    @GetMapping(value="/GetAllTestPlan")
    public Result GetAllTestPlan() {
//        System.out.println("controller层 GetAllTestPlan");
        ArrayList<TestPlan> testPlanList = TestPlanService.getAllTestPlan();
        if (Objects.nonNull(testPlanList)){
            return Result.ok(testPlanList);
        }
        else return Result.error("测试计划不存在");
    }

    @PostMapping(value="/CreateTestPlan")
    public Result CreateTestPlan(@RequestBody TestPlan testPlan) {
//        System.out.println("controller层 CreateTestPlan");
//        System.out.println(testPlan);
        int result = TestPlanService.CreateTestPlan(testPlan);
        if (result == -1){
            return Result.error("测试计划创建失败");
        }
        else {
            return Result.ok(result);
        }
    }

    @PostMapping(value="/SetTestPlanFinish")
    public Result SetTestPlanFinish(@RequestParam("planId") int planId) {
        int result = TestPlanService.SetTestPlanFinish(planId);
        if (result == -1){
            return Result.error("测试计划更新失败");
        }
        return Result.ok();
    }
}
